package com.itheima.web.controller;

import com.itheima.web.manager.UserManager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class UserController {

    @Autowired
    private UserManager userManager;

    // 分页查询用户列表
    @GetMapping("/manage/users")
    public ResponseEntity findUserInfoByPage(
            @RequestParam(value = "page", defaultValue = "1") Integer pageNum,
            @RequestParam(value = "pagesize", defaultValue = "10") Integer pageSize) {
        // 调用manager
        return userManager.findUserInfoByPage(pageNum, pageSize);
    }

    // 用户详情
    @GetMapping("/manage/users/{userId}")
    public ResponseEntity findUserInfoById(@PathVariable Long userId) {
        // 调用manager
        return userManager.findUserInfoById(userId);
    }

    // 动态列表
    @GetMapping("/manage/messages")
    public ResponseEntity findMovementByPage(
            Long uid,
            Integer state,
            @RequestParam(value = "page", defaultValue = "1") Integer pageNum,
            @RequestParam(value = "pagesize", defaultValue = "10") Integer pageSize) {

        // 调用manager
        return userManager.findMovementByPage(uid, state, pageNum, pageSize);
    }

    // 动态详情
    @GetMapping("/manage/messages/{movementId}")
    public ResponseEntity findMovementById(@PathVariable String movementId) {
        // 调用manager
        return userManager.findMovementById(movementId);
    }

    // 评论列表
    @GetMapping("/manage/messages/comments")
    public ResponseEntity findCommentVoByPage(
            String messageID,
            @RequestParam(value = "page", defaultValue = "1") Integer pageNum,
            @RequestParam(value = "pagesize", defaultValue = "10") Integer pageSize) {
        // 调用manager
        return userManager.findCommentVoByPage(messageID, pageNum, pageSize);
    }

    // 查询用户视频列表
    @GetMapping("/manage/videos")
    public ResponseEntity findMyVideoVoByPage(
            Long uid,
            @RequestParam(value = "page", defaultValue = "1") Integer pageNum,
            @RequestParam(value = "pagesize", defaultValue = "10") Integer pageSize) {
        // 调用manager
        return userManager.findMyVideoVoByPage(uid, pageNum, pageSize);
    }
}
